Repository navigation
fix(service-cache): report the derived Redis connection into the cluster driver's liveness - #31787
Conversation
…ter driver's liveness The shared cache's connection (base.duplicate()) had no error listener, so every reconnect during a Redis outage printed "[ioredis] Unhandled error event" with a stack. The listener style the redis driver uses is hoisted into service-cluster (ClusterDriverLiveness.watchConnection, reached from a derived connection through watchClusterDriverConnection); the redis driver's watchRedisConnection delegates to it, and the cache plugin watches the connection it derives, detaching before its deliberate quit. Claude-Session: https://claude.ai/code/session_01ADHkmSTGuRMEEW3vjJtdVG Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmSTGuRMEEW3vjJtdVG Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 3 package(s): 2 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 9 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin ad6733450ba518a73383a302a8b1c3f637e4af0e && git checkout ad6733450ba518a73383a302a8b1c3f637e4af0e
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin e253f3ab09717234fedae8e4d7a193cd1a12b0da c9c845d29e5d1acf4475a078aadfca1bed8ea176 && git checkout -B drift-repro e253f3ab09717234fedae8e4d7a193cd1a12b0da && git merge --no-ff c9c845d29e5d1acf4475a078aadfca1bed8ea176
node scripts/docs-audit/affected-docs.mjs --json e253f3ab09717234fedae8e4d7a193cd1a12b0da
|
|
domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flagsBoth os-dev-report open questions (6731816771) are answered in the seat ACCEPT:
Implemented-by: VERDICT: PASS |
|
domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM 维护者速读
席位核对 — ACCEPT · domain:server#2 · Head-sha
|
Requested by Steve · project thread
Fixes #31723
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
packages/services/service-cache/src/cache-service-plugin.ts(接线与关停顺序)、packages/services/service-cluster/src/cluster-resync.ts(watchConnection/watchClusterDriverConnection)、packages/services/service-cluster-redis/src/client.ts(委托)。pnpm --filter @objectstack/service-cache exec vitest run src/cache-service-plugin.topology.test.ts,预期 25/25 通过。What changes
@objectstack/service-cluster:ClusterDriverLiveness.watchConnection(client, source)is now the one listener style for a driver's connections (errorand an unexpectedclosereport down,readyreports up). The client is typed structurally (on/off/status), so the package stays ioredis-free. New exportwatchClusterDriverConnection(cluster, client, source)resolves the liveness through the module's own private reader and returns a no-op disposer when none is offered.@objectstack/service-cluster-redis:watchRedisConnectiondelegates toliveness.watchConnection. Its signature and behaviour are unchanged, and its tests are untouched and green.@objectstack/service-cache: the plugin watches only the connection it derives from the driver's (duplicate()), as source'cache'. One outage now logs one warning across command, subscriber and cache, andcluster.resyncwaits until the cache's connection is back too. The shutdown hook detaches beforecache.close()quits that connection, so a deliberate shutdown is not an outage.ClusterDriverLivenessof its own, logging through the plugin's logger. Its outage is logged once, credential-free, in the same text the driver uses. It is not silent, because the card asks for no silent swallow, and it is never once per attempt. Nothing subscribes to that private liveness's resync.redis.client(its owner listens), a borrowed client that cannotduplicate(), and the memory cache (no connection).Tests
New top-level
describeincache-service-plugin.topology.test.ts(the existing harness file):[ioredis] Unhandled error event, one warning, no credential, healthdown/outages: 1, and no plugin-level warning.close, as ioredis does) leaves the livenessupwith 0 outages and no warning.cluster.resyncwaits for the cache's connection: command back gives 0 resyncs, cache back gives exactly 1.New
describeincluster-resync.test.ts:watchClusterDriverConnectionreports into the offered liveness and its disposer detaches all three listeners. CONTROL: on the memory driver it attaches nothing.No existing test was edited.
Acceptance notes
watchClusterDriverConnection, the hoist adds one public member,ClusterDriverLiveness.watchConnection. It is the shared inner thatwatchRedisConnectiondelegates to (a liveness is already in hand there, pubsub's private one included). This is listed for the seat's ruling.Verification
Head
c9c845d2.RED on main (src of the four production files restored from origin/main c2bb879, rebuilt)
Tests 4 failed | 21 passed (25). Tests 1 and 2 each saw three"[ioredis] Unhandled error event:"lines. Test 3:expected 'unknown' to be 'up'(nothing watched). Test 4:TypeError: liveness.watchConnection is not a function. The ablation A1 below gives this test its behavioural red.GREEN and package runs
Topology file
Tests 25 passed (25). Under the lock, build plustypecheckplustestfor service-cluster (145/145, 11 files), service-cluster-redis (41/41, 4 files, the real-redis outage test included) and service-cache (79/79, 5 files):VERDICT command-exit 0.eslint --no-inline-configon the threesrcdirs: exit 0.Ablations (scripts/ablation-replace.mjs; each restored, blob == HEAD)
? (() => {})): 4 failed (tests 1–4).await cache.close(); unwatch();): 1 failed (test 3, the driver's "lost its connection … connection closed" warning appears).if (true)): 1 failed (test 2).watchClusterDriverConnectionalways a no-op: 1 failed (the service-cluster pin).Gates
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstackderived 66 commands on head c9c845d; all 66 ran locally with exit 0. Three first read exit 3 on prerequisites (the teardown self-test's pinned fixture commit, fetched; two gates needing package dists, built withturbo run build --filter='./packages/**', 81/81) and re-ran exit 0.--ranreconciliation: "66 derived famil(ies) accounted for — 66 run, 0 NOT-MEASURED". Families CI runs beyond the derived set are left to the PR's check-runs.Generated by Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_01ADHkmSTGuRMEEW3vjJtdVG